﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace System.Data
{
    public interface IRepository<T> where T: BaseEntity
    {
        /// <summary>
        /// Create New Instance
        /// </summary>
        /// <returns></returns>
        T NewEntity();
        T GetById(object id);
        void Add(T entity);
        void BulkCopy(DataTable dt);
        void BulkCopy(IList<T> list);
        void Update(T entity);
        void Delete(T entity);
        /// <summary>
        /// Get an item matching to prediate
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        T FirstOrDefault(Expression<Func<T, bool>> predicate);
        IQueryable<T> GetList(Expression<Func<T, bool>> predicate);
        IQueryable<T> Table { get; }
        /// <summary>
        /// 执行Sql语句
        /// </summary>
        /// <example>Query("SP_Test @p0,@p1", "138822242694","0")</example>
        /// <typeparam name="TElement">结果的实体类型</typeparam>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        IEnumerable<TElement> Query<TElement>(string commandText, params object[] parameters);
       
    }
}
